package com.tyros.common.kit.web.mybatis;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/**
 * @author zhangshuaiyin
 * @date 2022/7/2 19:51
 */
public class DefaultMetaObjectHandler implements MetaObjectHandler {
    private final static String OPEN_ID = "openId";
    private final static String CREATE_TIME = "createTime";
    private final static String UPDATE_TIME = "updateTime";

    @Override
    public void insertFill(MetaObject metaObject) {
        this.fillStrategy(metaObject, OPEN_ID, IdUtil.fastSimpleUUID());
        this.fillStrategy(metaObject, CREATE_TIME, LocalDateTime.now());
        this.fillStrategy(metaObject, UPDATE_TIME, LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.fillStrategy(metaObject, UPDATE_TIME, LocalDateTime.now());
    }
}
